#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>

int main()
{
	int sfd = shm_open("/shm_webserver", O_RDWR | O_CREAT, 0666);
	if (sfd < 0) {
		perror("can not create share memory");
		exit(0);
	}
	if (ftruncate(sfd, sysconf(_SC_PAGESIZE)) < 0) {
		perror("can not alloc shm");
		exit(0);
	}
	char *addr = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_WRITE | PROT_READ, MAP_SHARED, sfd, 0);
	if (addr == MAP_FAILED) {
		perror("mmap 1");
		exit(0);
	}

	char data[] = "Linux 系統中的 dd 指令是一個多功能的小工具";
	strcpy(addr, data);
	printf("%s", addr);

	return 0;
}